package com.whmnx.my.ui.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableList;

import com.whmnx.base.bean.BagListBean;
import com.whmnx.base.constants.Constants;
import com.whmnx.base.http.CallBack;
import com.whmnx.base.http.HttpClient;
import com.whmnx.my.BR;
import com.whmnx.my.R;
import com.whmnx.my.ui.fragment.BodouFragment;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

/**
 * author : huang
 * date   : 2020/9/29 0029 10:45
 * version: 1.0
 */
public class Bodou1Model extends BaseViewModel {

    public BodouFragment mFragment;
    public Bodou1Model(@NonNull Application application) {
        super(application);

    }

    public void initToolbar(BodouFragment bodouFragment) {
        this.mFragment = bodouFragment;
        getBeanBagList();
    }

    private void getBeanBagList() {
        Map<String, Object> params = new HashMap<>();
        HttpClient.get(mFragment.getActivity(), Constants.GETBEANBAGLIST, params,new CallBack<List<BagListBean>>() {
            @Override
            public void onSuccess(List<BagListBean> bagListBeans) {
                observableList.clear();
                for (BagListBean bagListBean : bagListBeans) {
                    observableList.add(new BodouItemViewModel(Bodou1Model.this,bagListBean));
                }
            }
        });
    }


    //给RecyclerView添加ObservableList
    public ObservableList<BodouItemViewModel> observableList = new ObservableArrayList<>();
    //给RecyclerView添加ItemBinding

    public ItemBinding<BodouItemViewModel> itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_bodou);


}
